<template>
  <div>
    <!-- 轮播图 -->
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="item in image" :key="item.id">
        <img v-lazy="item.imgSrc" />
      </van-swipe-item>
    </van-swipe>
    <!-- 搜索 -->
    <div class="search">
      <search></search>
      <van-icon
        name="map-marked"
        size="25"
        color="white"
        @click="$router.push('/map')"
      />
    </div>
    <!-- 租房 -->
    <van-grid :border="false">
      <van-grid-item to="/find">
        <div class="icon-box">
          <van-icon name="wap-home-o" size="30" color="#04af68" />
        </div>
        <span class="icon-text">整租</span>
      </van-grid-item>
      <van-grid-item to="/find">
        <div class="icon-box">
          <van-icon name="friends-o" size="30" color="#04af68" />
        </div>
        <span class="icon-text">合租</span>
      </van-grid-item>
      <van-grid-item to="/map">
        <div class="icon-box">
          <van-icon name="map-marked" size="30" color="#04af68" />
        </div>
        <span class="icon-text">地图找房</span>
      </van-grid-item>
      <van-grid-item to="">
        <div class="icon-box">
          <van-icon name="home-o" size="30" color="#04af68" />
        </div>
        <span class="icon-text">去出租</span>
      </van-grid-item>
    </van-grid>
    <!-- 租房小组 -->
    <rental-group-item :list="rentalList"></rental-group-item>
    <!-- 最新资讯 -->
    <latest-news-item :list="newsList"></latest-news-item>
    <!-- 占位 -->
    <div class="kong"></div>
  </div>
</template>

<script>
import { swiper, getRentalGroup, getNewsList, imgStitching } from '@/api/home'
import RentalGroupItem from '@/components/RentalGroupItem.vue'
import LatestNewsItem from '@/components/LatestNewsItem.vue'
import Search from '@/components/search.vue'
export default {
  name: 'HomePage',
  components: { RentalGroupItem, LatestNewsItem, Search },
  props: {},
  data () {
    return {
      image: [], // 轮播图
      rentalList: [], // 租房小组
      newsList: []// 最新资讯
    }
  },
  watch: {},
  computed: {},
  created () {
    this.getImageUrl()
    this.getRentalGroup()
    this.getNewsList()
  },
  mounted () {},
  methods: {
    // 轮播图
    async getImageUrl () {
      const { data: { body } } = await swiper()
      const res = imgStitching(body)
      this.image = res
    },
    // 租房小组
    async getRentalGroup () {
      const { data: { body } } = await getRentalGroup()
      const res = imgStitching(body)
      this.rentalList = res
    },
    // 最新资讯
    async getNewsList () {
      const { data: { body } } = await getNewsList()
      const res = imgStitching(body)
      this.newsList = res
    }
  }
}
</script>
<style lang="less" scoped>
.my-swipe .van-swipe-item {
  position: relative;
  // background-color: #39a9ed;
  height: 212px;
}
/deep/.van-toast{
  background-color: #ffffff00 !important;
  color: #aeaeae;
}
img {
  width: 100%;
}
.search{
  display: flex;
  align-items: center;
  position: absolute;
  top: 1px;
  z-index: 9999;
  padding: 10px;
}
.icon-box {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 50px;
  height: 50px;
  background-color: #f2fbf7;
  border-radius: 50%;
}
.icon-text {
  font-size: 14px;
  margin-top: 5px;
}
.kong{
  height: 50px;
}
</style>
